package com.gxa.zhonglong.controller;

import com.gxa.zhonglong.common.JsonResult;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.pojo.GoodsClass;
import com.gxa.zhonglong.pojo.GoodsType;
import com.gxa.zhonglong.service.GoodsClassService;
import com.gxa.zhonglong.service.GoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author NITRO
 */

@Api
@CrossOrigin
@RestController
@RequestMapping("/goodsClass")
public class GoodsClassController {

    @Autowired
    private GoodsClassService goodsClassService;

    @ApiOperation(value = "添加商品分类")
    @PostMapping("/addGoodsClass")
    public Map addGoodsClass( GoodsClass goodsClass) throws BusinessException {
        JsonResult jsonResult=new JsonResult();
        goodsClassService.add(goodsClass);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }


    @PostMapping("/deleteGoodsClass")
    @ApiOperation("删除商品分类")
    public Map<String,Object> deleteGoodsClass(@RequestBody Map<String,List<Long>> ids) throws BusinessException {
        goodsClassService.delete(ids.get("ids"));
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "修改商品分类")
    @PostMapping("/updateGoodsClass")
    public Map updateClass( GoodsClass goodsClass) throws BusinessException {
        JsonResult jsonResult = new JsonResult();
        goodsClassService.update(goodsClass);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @ApiOperation(value = "查询商品分类")
    @PostMapping("/getGoodsClassList")

    public Map getGoodsClassList(){


        List<GoodsClass> list = goodsClassService.getList();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(list);
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }
}
